package com.ajax.servlet; /**
 * @author wzm
 * @create 2023-03-23 10:42
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/ajax01")
public class AjaxServlet01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("ajax访问了servlet");
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        //获取请求的参数
        String username = request.getParameter("username");
        System.out.println("username = " + username);

        //响应一些数据给浏览器
        response.getWriter().write("恭喜你，访问成功");


    }
}
